import axios from 'axios'
import { Fetcher } from 'swr'

import { App, ChatMessage, ChatSession } from '@prisma/client'

const get = async (url: string, params: Record<string, any>) => {
    const result = await axios.get(url, { params })
    return result.data
}

export const fetchApps: Fetcher<App[], { url: string, params: Record<string, any> }> = async ({ url, params }) => get(url, params)
export const fetchChatSessions: Fetcher<ChatSession[], { url: string, params: Record<string, any> }> = async ({ url, params }) => get(url, params)
export const fetchChatMessages: Fetcher<ChatMessage[], { url: string, params: Record<string, any> }> = async ({ url, params }) => get(url, params)